package cn.gcjxsc.payment.messaging.sink;

import cn.gcjxsc.common.data.notify.CancelOrderData;
import cn.gcjxsc.payment.task.OrderTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.Input;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.Message;
import org.springframework.messaging.SubscribableChannel;

/**
 * 取消订单通知.
 *
 * @author pumbaa
 * @since 1.0
 */
@EnableBinding(TradeCancelSink.Sink.class)
public class TradeCancelSink {
    @Autowired
    private OrderTaskService taskService;

    @StreamListener(Sink.QUE_NAME)
    public void process(Message<CancelOrderData> message) {
        CancelOrderData payload = message.getPayload();
        if (null != payload) {
            try {
                taskService.cancelOrderTask(payload.getTradeNo(), payload.getMinute(), payload.getType());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public interface Sink {
        String QUE_NAME = "rw_machine_payment_cancel_input";

        @Input(QUE_NAME)
        SubscribableChannel input();
    }


}
